<template>
  <div class="home">
    <el-container>
      <el-aside width="auto">
        <router-link to='/home'>
          <div class="logo"></div>
        </router-link>
        <el-menu
          class="el-menu-vertical-demo el-menu-admin"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          :unique-opened='true'
          :router='true'
          :collapse='collapse'
        >
            <el-menu-item index="user">
              <template slot="title">
                <i class="el-icon-star-off"></i>
                <span>用户管理</span>
              </template>
            </el-menu-item>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-news"></i>
              <span>分类管理</span>
            </template>
            <el-menu-item index="categoryFirst">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>一级分类管理</span>
              </template>
            </el-menu-item>
            <el-menu-item index="categorySecond">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>二级分类管理</span>
              </template>
            </el-menu-item>
          </el-submenu>
          <el-menu-item index="productList">
              <template slot="title">
                <i class="el-icon-setting"></i>
                <span>商品管理</span>
              </template>
            </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <a href="javascrip:;" @click='collapse=!collapse'  class="myicon myicon-menu toggle-btn"></a>
          <div><span class="welcome">欢迎你：{{$store.state.username?$store.state.username :
          $store.getters.username}}</span> <span @click='loginout' class="loginout">退出</span></div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {Loginout} from '@/api'
export default{
  data () {
    return {
      collapse: false
    }
  },
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    },
    loginout () {
      Loginout()
        .then(res => {
          console.log(res)
          this.$router.push('/login')
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.home {
  height: 100%;
  .el-menu-admin:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .el-container {
    height: 100%;
  }
  .el-aside {
    background-color: #545c64;
  }
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #545c64;
  }
  .logo {
    height: 60px;
    background: url(../assets/logo.png);
    background-size: cover;
    background-color: #ffffff;
  }
  .toggle-btn {
    padding: 0 15px;
    margin-left: -20px;
    font-size: 36px;
    color: white;
    cursor: pointer;
    line-height: 60px;
    &:hover {
      background-color: #4292cf;
    }
  }
  .system-title {
    font-size: 28px;
    color: white;
  }
  .welcome {
    color: white;
  }
  .loginout{
    cursor: pointer;
  }
}
</style>
